package com.example.netty_pipline.pipeline.handler;

import com.example.netty_pipline.pipeline.ChannelHandlerContext;
import com.example.netty_pipline.pipeline.ChannelInboundHandler;

/**
 * 业务处理器 - 处理具体的业务逻辑
 */
public class BusinessHandler implements ChannelInboundHandler {
    
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof String) {
            String message = (String) msg;
            System.out.println("[BusinessHandler] Processing: " + message);
            
            // 模拟业务处理
            String response = "Processed: " + message.toUpperCase();
            
            // 写入响应
            ctx.pipeline().write(response);
            ctx.pipeline().flush();
        } else {
            ctx.fireChannelRead(msg);
        }
    }
}